<?php

namespace App\Service\Index\v1_3_3;

use App\Model\UserProfile;
use App\Service\BaseService;

/**
 * 首页功能入口
 */
class MainExtranceService extends BaseService
{
    public function handle()
    {
        $appId = $this->request->input('appid', '');
        $channel = $this->request->input('channel', '');
        $version = $this->request->input('version', '');
        $forbidEntrance = config('busi.forbidEntrance');

//        return ['list' => []];
        if(empty($channel)) return ['list' => []];

//        if ($channel == 1002){
//            return ['list' => []];
//        }

        if (
            in_array($appId, explode(',', env('MAIN_EXTRANCE_FORBID', '')))
            || (($forbidEntrance && isset($forbidEntrance[$channel]) && version_compare($version,$forbidEntrance[$channel],'=')) )
        ) {
            return ['list' => []];
        }



        $userId = $this->getUserId();
        $profile = UserProfile::getProfile($userId);
        $ret['list'] = [
//            ['name' => '视频速配', 'type' => 'video_match', 'sub_title' => '真人视频聊天'],
//            ['name' => '语音速配', 'type' => 'voice_match', 'sub_title' => '语音陪聊入睡'],
//            ['name' => '福利中心', 'type' => 'daily_task', 'sub_title' => '获取免费福利'],
        ];

        if ($profile->gender == 1)
        {
            $ret['list'] = array_merge($ret['list'],[
//                ['name' => '视频速配', 'type' => 'video_match', 'sub_title' => '真人视频聊天'],
//                ['name' => '语音速配', 'type' => 'voice_match', 'sub_title' => '语音陪聊入睡'],
            ]);
        }

        if ($profile->gender == 0)
        {
            $ret['list'] = array_merge($ret['list'],[
//                ['name' => '福利中心', 'type' => 'daily_task', 'sub_title' => '获取免费福利'],
            ]);
        }


        if (
            !in_array($this->appId, explode(',', env('FORBID_INVITE_LINK_APPID', '')))
            || $this->curVersion < env('FORBID_INVITE_LINK_VERSION', '1.4.1')
        ) {
            $forbidEntrance = config('busi.forbidEntrance_invitation');

            if (
                !((!empty($forbidEntrance) && isset($forbidEntrance[$channel]) && version_compare($version,$forbidEntrance[$channel],'=')))
                && $profile->gender == 0
            ) {
                $rewardConfig = (config('act.invite.reward.recharge') + config('act.invite.act.0.reward_recharge')) * 100;
//                $ret['list'][] = ['name' => '邀请有奖', 'type' => 'invite', 'sub_title' => '得'. $rewardConfig .'%返利'];
//                $ret['list'][] = ['type' => 'invite'];
            }



        }

        if ($profile->gender == 1) $ret['list'][] = ['name' => '免费通话', 'type' => 'free_call', 'sub_title' => '获取免费福利'];
        else $ret['list'][] = ['name' => '排行榜', 'type' => 'rank', 'sub_title' => ''];
        return $ret;
    }
}
